<?php

namespace SummoIngenio\Sai\MatematicaBundle\Utility\Juego\P0;
use SummoIngenio\Sai\MatematicaBundle\Utility\Juego\JuegoBase;

/**
 * Description of P01070
 *
 * @author SVM
 */
class P01070 extends JuegoBase {

  public function init() {
   $pina = 8;
   $manzana = 6;
   $banano = 5;
   $naranja = 5;
   $this->banano = 0;
   $this->naranja = 0;   
   $this->pina = 0;
   $this->manzana = 0;
   $pn = rand(true,false);
   $mz = rand(true,false);
   $bn = rand(true,false);
   $nr = rand(true,false);
   
   $this->pina = rand(0,2);
   if($this->pina<=1){
       $this->manzana = rand(1,2);
       if($this->manzana<=1){
           $this->banano = rand(0,1);
           if($this->banano ==0 ){
               $this->naranja = rand(0,1);
           }
       }
   }else{
       if($this->pina==0){
        $this->manzana = rand(1,3);
        if($this->manzana<3){
            $this->banano = rand(0,3-$this->manzana);
            if($this->banano ==0){
                $this->naranja = rand(1,3-$this->manzana);
            }
            if($this->banano ==3){
                $this->naranja = rand(0,1);
            }
        }
       }
   }
   
  }
  
  public function getPregunta() {
    return $this->render('P0/P01070/pregunta', array());
  }
  
  public function getHtmlDesactivado() {
    return $this->render('P0/P01070/desactivado', array(
      'banano'     => $this->banano,
      'manzana'     => $this->manzana,        
      'pina'     => $this->pina,              
      'naranja'     => $this->naranja,
    ));
  }
  
  public function getHtmlJugable() {
    return $this->render('P0/P01070/jugable', array(
      'banano'     => $this->banano,
      'manzana'     => $this->manzana,        
      'pina'     => $this->pina,              
      'naranja'     => $this->naranja,
    ));
  }
  
  public function getHtmlResuelto() {
    return $this->render('P0/P01070/resuelto', array(
      'banano'     => $this->banano,
      'manzana'     => $this->manzana,        
      'pina'     => $this->pina,              
      'naranja'     => $this->naranja,
    ));
  }
  
  public function verificarRespuesta($respuestaUsuario) {
    $resp = true;
        $cantidad = "5*".$this->banano."+"."6*".$this->manzana."+"."8*".$this->pina."+"."5*".$this->naranaja;
        if((5*$this->banano + 6*$this->manzana + 8*$this->pina +5*$this->narajana)!=$respuestaUsuario->get('valor1')){
            $resp = false;
        }
    $aRetornar = array(
      'respuesta' =>  $cantidad,
      'correcta'  =>  $resp,
    );
    return $aRetornar;
  }

  public function getJavascript() {
    $aRetornar = array(
      "tipo"      => "archivo",
      "contenido" => "P0/P01070.js"
    );
    return $aRetornar;
  }

  public function getCss() {
    $aRetornar = array(
      "tipo"      => "archivo",
      "contenido" => "P0/P01070.css"
    );
    return $aRetornar;
  }

  public function __sleep() {
    return array(
      'banano',
      'manzana',        
      'pina',        
      'naranja',        
    );
  }
}